/**
 * SEVAS - Swiss Electronic Vaccination Advisor Service / Agile Development
 *
 * $Id: Vaccination.java 41 2010-08-24 03:15:52Z zimmr7@bfh.ch $
 */
package ch.bfh.sevas;

import java.util.ArrayList;
import java.util.List;

public class RecommendedBaseVaccination {

    public RecommendedBaseVaccination(Age minimumAge) {
        vaccinationAges = new ArrayList<Age>();
        vaccinationAges.add(minimumAge);
    }

    public RecommendedBaseVaccination(List<Age> ages) {
        vaccinationAges = ages;
    }

    public RecommendedBaseVaccination(String antigen,
            String code,
            String vaccine,
            String manufacturer,
            String dose,
            List<Age> ages) {
        this.antigen = antigen;
        this.code = code;
        this.vaccine = vaccine;
        this.manufacturer = manufacturer;
        this.dose = dose;
        vaccinationAges = ages;
    }

    public boolean IsFirstVaccinationDue(Age age) {
        int minAgeWithMargin = (vaccinationAges.get(0).AgeInDays() * 9 / 10);
        boolean isDue = (age.AgeInDays() >= minAgeWithMargin);
        return isDue;
    }

    public boolean IsVaccinationDue(Age age, int numPreviouslyAdministered) {
        int numRecommended = NumVaccinationsUpToAge(age);

        int numRequiredVaccinations = numRecommended - numPreviouslyAdministered;

        if (numRequiredVaccinations == 1) {
            return true;
        } else if (numRequiredVaccinations <= 0) {
            return false;
        } else {
            throw new UnsupportedOperationException("Es wurden Impfungen ausgelassen. Dies wird momentan noch nicht unterstützt.");
        }
    }
    private String antigen;
    private String code;
    private String vaccine;
    private String manufacturer;
    private String dose;
    private List<Age> vaccinationAges;

    private int NumVaccinationsUpToAge(Age age) {
        int numVacc = 0;
        int patientAgeInDays = age.AgeInDays();

        for (int i = 0; i < vaccinationAges.size(); i++) {
            int vaccAgeWithMargin = (vaccinationAges.get(i).AgeInDays() * 9 / 10);
            if (patientAgeInDays >= vaccAgeWithMargin) {
                numVacc++;
            }
        }
        return numVacc;
    }

    public String getAntigen() {
        return antigen;
    }

    public String getCode() {
        return code;
    }

    public String getVaccine() {
        return vaccine;
    }

    public String getManufacturer() {
        return manufacturer;
    }

    public String getDose() {
        return dose;
    }

    public List<String> getVaccinationAges() {
        List<String> result = new ArrayList<String>();
        for (Age age : vaccinationAges) {
            result.add(age.getVaccinationAge());
        }
        return result;
    }
}
